package com.xiaobange.controller;

import com.xiaobange.utils.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @version 1.0
 * @Author 小班哥
 * @Date 2025/5/11 16:33
 * @Explain
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private RedisCache redisCache;

    @GetMapping("/addLock")
    public String lock(){
        Boolean b = redisCache.redisTemplate.opsForValue().setIfAbsent("key", "uuid", 10, TimeUnit.SECONDS);
        return "当前状是：" + b;
    }

    @GetMapping("/delLock")
    public String del(){
        boolean b = redisCache.deleteObject("key");
        return "当前状是：" + b;
    }

}
